﻿#include <libcomm.h>

class MyThreadPool : public ThreadPool
{
public:
	MyThreadPool(int num) : ThreadPool(num,"tst") {}
	virtual int Process(int index)
	{
		printf("%d. test begin ....\n",index);
		//Thread::Sleep(300);
		//printf("test end.\n");
		return 100;
	}
};

int main(int argc, char *argv[])
{
	Application::CatchDumpWhenCrash();
	printf("version: %s\n", common_version());

	
	/*BmpBuffer bmp("1.bmp");
	printf("%d*%d*%d; %d;%d;%d==%d;\n", bmp.width(), bmp.height(), bmp.channels(),
		bmp.headerSize(), bmp.rawSize(), bmp.size(), bmp.headerSize() + bmp.rawSize());
	bmp.reverseRaw();
	File::SaveContent("r2.bmp", bmp.get(), bmp.size());

	String b64 = CodecBase64::Encode(bmp.get(), bmp.size());
	Buffer buf = CodecBase64::Decode(b64);
	File::SaveContent("s2.bmp", buf.get(), buf.size());

	return 0;*/
	

	
	/*String a = "";
	String base64 = CodecBase64::Encode(a.get(),a.length()+1);
	printf("%s.\n", base64.get());
	Buffer decode = CodecBase64::Decode(base64);
	printf("%s.\n", decode.get());
	return 0;*/

	/*
	Buffer bmp = File::LoadContent(Application::GetModuleDirectoryPath() + "/a.bmp");
	printf("bmp size: %d.\n", bmp.size());
	String base64 = CodecBase64::Encode(bmp);
	printf("base64 length: %d;%d.\n", base64.length(),base64.length() % 4);

	Buffer bmp2 = CodecBase64::Decode(base64);
	printf("bmp2 size: %d.\n", bmp2.size());
	File::SaveContent(Application::GetModuleDirectoryPath() + "/b.bmp", bmp2.get(), bmp2.size());
	*/
	
	int exitcode;
	MyThreadPool trd(100);
	for (int i=0;i<10;i++)
	{
		trd.Start();
		Thread::Sleep(100);
		trd.Stop();
	}
	//trd.Run();
	//exitcode = trd.Join(1000);
	//printf("1.exit code: %d.\n", exitcode);
	////trd.Run();
	//trd.Terminate();
	//exitcode = trd.Join();
	//printf("2.exit code: %d.\n", exitcode);
	//exitcode = trd.Join();
	//printf("3.exit code: %d.\n", exitcode);

	
	
	return 0;
}